<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分类添加</title>
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<script type="text/javascript" src="../static/js/WdatePicker/WdatePicker.js"></script>
<%
String parentid =request.getParameter("parentid");
String para =request.getParameter("f_catalog_programatype");
int f_catalog_programatype = 1;
if(para != null)
	f_catalog_programatype = Integer.valueOf(para);
String []nonceObj=ConstantUtils.getNonceObject();
%>
</head>
<body>
<div id="right" style="width: 100%; overflow: auto; float: right">
		<div id="container">
			<div class="editspace">
				<form id="contentForm" class="cmxform" enctype="multipart/form-data"
					name="formName">
					<input type="hidden" name="f_catalog_programatype" value="<%=f_catalog_programatype%>"/>
					<input type="hidden" name="stime" value="<%=nonceObj[0]%>"/>
					<input type="hidden" name="sign" value="<%=nonceObj[1]%>"/>
					<input type="hidden" id="f_catalog_id" name="f_catalog_id" value="" />
					<input type="hidden" id="f_catalog_parentid" name="f_catalog_parentid" value="" /> 
					<legend>分类新增</legend>
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">
											*
										</span>
										分类名称：
									</td>
									<td width="70%">
										<input type="text" name="f_catalog_name" id="f_catalog_name" style="width: 150px;" value=""/> 
									</td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">
											*
										</span>
										分类排序：
									</td>
									<td width="70%">
										<input type="text" name="f_catalog_viewindex" id="f_catalog_viewindex" style="width: 150px;" value=""/> 
									</td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										分类路径：
									</td>
									<td width="70%">
										<input type="text" name="f_catalog_url" id="f_catalog_url" style="width: 150px;" value=""/> 
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					
					<fieldset>
						<div class="fitem">
								<table width="100%" border="0" cellpadding="0" cellspacing="0">
									<tr>
										<td width="30%" align="right">
											开放时间：
										</td>
										<td width="70%">
											<input id="f_catalog_starttime" name="f_catalog_starttime" type="text" style="width: 150px;" onClick="WdatePicker({skin:'default',dateFmt: 'yyyy-MM-dd HH:mm:ss'})" value="" class="yl_inp yw_name" />
										</td>
									</tr>
								</table>
						</div>
					</fieldset>	
						
					<fieldset>	
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										关闭时间：
									</td>
									<td width="70%">
										<input id="f_catalog_endtime" name="f_catalog_endtime" type="text" style="width: 150px;" onClick="WdatePicker({skin:'default',dateFmt: 'yyyy-MM-dd HH:mm:ss'})" value="" class="yl_inp yw_name" />
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">
											*
										</span>
										产品：
									</td>
									<td width="70%">
										<select id="f_catalog_productid" name="f_catalog_productid" style="width: 150px;">
				                    		<option value="0">--请选择--</option>
				                    	</select>								
									</td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">
											*
										</span>
										分类状态：
									</td>
									<td width="70%">
										<select name="f_catalog_status" id="f_catalog_status" style="width: 150px;">
												<option value="1">有效</option>
												<option value="2">无效</option>
										</select>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					
					<!-- <fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										业务类：
									</td>
									<td width="70%">
										<input readonly="readonly" type="text" style="width: 150px;" id="f_catalog_class" name="f_catalog_class" value=""/>
									</td>
								</tr>
							</table>
						</div>
					</fieldset> -->
					
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										分类描述：
									</td>
									<td width="70%">
										<textarea cols="20" rows="4" style="resize:none; width:150px;" id="f_catalog_desc" name="f_catalog_desc">
											
										</textarea>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="left">
										<jsp:include page="../pictures/pictures_add.jsp">
											<jsp:param name="picType" value="分类" />
										</jsp:include>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
				</form>
			</div>
			<div class="toolbar" style="text-align: center;">
				<a id="easyui-linkbutton" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);" onclick="_submitFm()">
					保存
				</a> 
				<a href="javascript:void(0);" data-options="iconCls:'icon-cancel'" class="easyui-linkbutton" onclick="javascript:parent.$('#dlg').dialog('close')">
					取消
				</a>
			</div>
		</div>
	</div> 
</body>
<script type="text/javascript">
$(function(){
	$("#contentForm").validate({
		rules: {
			f_catalog_name: {
				required: true,
				minlength: 1,
				maxlength: 50
			},
			f_catalog_viewindex:{
				required:true
			},
			f_catalog_productid:{
				min:1
			},
			f_catalog_starttime: {
				required: true,
				date: true
			},
			f_catalog_endtime: {
				required: true,
				date: true
			}
		},
		messages: {
			f_catalog_name: {
				required: "请输入分类名称",
				minlength: "分类名称不能少于1位",
				maxlength: "分类名称不能超过50位"
			},
			f_catalog_viewindex:{
				required: "请输入分类排序"
			},
			f_catalog_productid:{
				min: "请选择产品"
			},
			f_catalog_starttime: {
				required: "请选择开放日期",
				date: "请输入正确的日期"
			},
			f_catalog_endtime: {
				required: "请选择关闭日期",
				date: "请输入正确的日期"
			}
		},
		
	});
});
function GetRequest() {   
	   var url = location.search; //获取url中"?"符后的字串   
	   var theRequest = new Object();   
	   if (url.indexOf("?") != -1) {   
	      var str = url.substr(1);   
	      strs = str.split("&");   
	      for(var i = 0; i < strs.length; i ++) {   
	         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
	      }   
	   }   
	   return theRequest;   
}  
window.onload=function(){
	$.ajax({
		url:"../product/product_list.do",
		data: {f_sp_status: 1, f_sp_id: 0 ,page:1 ,rows:1000},
		success:function(data) {
			data = JSON.parse(data).rows;
			var str = "";
			for(var i=0;i<data.length;i++) {
				str+='<option value="'+data[i].f_sp_id+'">'+data[i].f_sp_name+'</option>';
			}
			$("#f_catalog_productid").append(str);
		}
	});
	var request=GetRequest();
	$("#f_catalog_id").val(0);
	$("#f_catalog_parentid").val(request.parentid);
	$("#f_catalog_name").val("");
	$("#f_catalog_viewindex").val(0);
	$("#f_catalog_productid").val(0);
	$("#f_catalog_url").val("");
	$("#f_catalog_desc").val("");
	$("#f_catalog_class").val("");
	$("#f_catalog_status").val(1);
}
function _submitFm() {
	 arrayToJson();
	 if($("#contentForm").validate().form()) {
			app_ajax('insert_catalog.do', $("#contentForm").serialize(), function(data){
				if(data.success) {
					$.messager.progress('close');
					$.messager.alert('提示', '提交成功！', 'info', function() {
						$('#dlg').dialog('close');
						//parent.gotoSearch($('#easyui-treegrid'));
						window.location.reload();
					});
				} else {
					$.messager.alert('提示', data.result, 'info', function() {
						$.messager.progress('close');
					});
				}
			});	
	 }
	 window.parent.leftFrame.location.href = "catalog_list.jsp?catalogId=<%=parentid%>&f_catalog_programatype=<%=f_catalog_programatype%>";
}
</script>
</html>